/*******************************************************************************
* @file pio_drv.c
* @author hai
* @version V1.0
* @date 2016-1-16
* @brief
********************************************************************************/
#include "Sys.h"
#include "Pio_drv.h"

/***********************************************************************
* @brief config gpioN pinX.
* @param
        gpio: GPIOA to GPIOD
        pin: GPIO_Pin_0 to GPIO_Pin_15, or conbine
        mode: GPIO_Mode_IN_FLOATING to  GPIO_Mode_Out_PP --GPIOMode_TypeDef   
        speed: GPIO_Speed_2MHz, GPIO_Speed_10MHz,GPIO_Speed_25MHz
* @retval None
************************************************************************/
void PIO_Config(GPIO_TypeDef *gpio, INT32U pin, GPIOMode_TypeDef mode, GPIOSpeed_TypeDef speed)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    INT32U tmp32 = 0;
 
    if (gpio == GPIOA){        
        tmp32 |= RCC_APB2Periph_GPIOA;
    }else if (gpio == GPIOB){
        tmp32 |= RCC_APB2Periph_GPIOB;
    }else if (gpio == GPIOC){
        tmp32 |= RCC_APB2Periph_GPIOC;
    }else if (gpio == GPIOD){
        tmp32 |= RCC_APB2Periph_GPIOD;
    }else{
        return;
    }
   
    RCC_APB2PeriphClockCmd(tmp32,ENABLE);

    GPIO_InitStructure.GPIO_Pin = pin;
    GPIO_InitStructure.GPIO_Mode = mode;
    GPIO_InitStructure.GPIO_Speed = speed;
    GPIO_Init(gpio,&GPIO_InitStructure);  

}


void PIO_Write(GPIO_TypeDef *gpio, INT32U pin, INT8U level)
{
    if (level != 0){
        gpio->BSRR |= pin;
    } else {
        gpio->BRR |= pin;       
    }
}

INT8U PIO_Read(GPIO_TypeDef *gpio, INT32U pin)
{
    if ((gpio->IDR & pin) != 0){
        return 1;
    }else{
        return 0;
    }
}



